import { messages } from "share/common";

/**
 *
 * @param bgtAmount 预算额
 * @param expReserveAmount 保留额
 * @param expUsedAmount 发生额
 * @param expAvailableAmount 可用额
 * @param schedule 预算进度
 * @returns {{title: {text: string, subtext: string, left: string, top: string, bottom: string, textVerticalAlign: string, padding: number, itemGap: number, textStyle: {fontWeight: number, fontSize: number, color: string, height: number}, subtextStyle: {fontWeight: number, fontSize: number, color: string, height: number}}, tooltip: {trigger: string, formatter: string}, series: {type: string, radius: string[], label: {normal: {show: boolean}}, data: Array, color: undefined}[]}}
 */
export function createOptions({ bgtAmount, expReserveAmount, expUsedAmount, expAvailableAmount, schedule }) {

  const COLOR_LIST = [
    "#4b8dff",
    "#4dc690",
    "#ddd",
  ];
  const OPTION_TEMPLATE = {
    title: {
      text: messages('expense-11.key29')/*预算进度*/,
      subtext: '0%',
      left: 'center',
      top: '45%',   // 这边居中实在不好弄
      bottom: 'center',
      textVerticalAlign: 'middle',
      padding: 0,
      itemGap: 5,
      textStyle: {
        fontWeight: 400,
        fontSize: 12,
        color: '#989898',
        height: 16
      },
      subtextStyle: {
        fontWeight: 400,
        fontSize: 16,
        color: '#1E2125',
        height: 24
      }
    },
    tooltip: {
      trigger: 'item',
      formatter: "{b}: {c} ({d}%)"
    },
    series: [
      {
        type: 'pie',
        radius: ['50%', '70%'],
        label: {
          normal: {
            show: false,
          },
        },
        data: [],
        color: undefined
      }
    ]
  };

  let dataList = [];

  OPTION_TEMPLATE.title.subtext = (schedule * 100).toFixed(3) + '%';
  dataList.push({
    value: expReserveAmount,
    name: messages('expense-11.key3')/*保留额*/
  });
  dataList.push({
    value: expUsedAmount,
    name: messages('expense-11.key4')/*发生额*/
  });

  // 预算进度超出时进度标红
  if (schedule > 1) {
    OPTION_TEMPLATE.title.subtextStyle.color = '#ff6680';
  }

  // 预算进度超出时实际上只展示保留额和发生额各自所占比例
  if (expReserveAmount + expUsedAmount > bgtAmount) {
    OPTION_TEMPLATE.series[0].color = COLOR_LIST.slice(0, 2);
  } else if (expReserveAmount === 0 && expUsedAmount === 0 && bgtAmount === 0) {  // 全部为0只显示可用额
    OPTION_TEMPLATE.series[0].color = COLOR_LIST.slice(2, 3);
    dataList = [{
      value: expAvailableAmount,
      name: messages('expense-11.key30')/*可用额*/
    }]
  } else {
    dataList.push({
      value: expAvailableAmount,
      name: messages('expense-11.key30')/*可用额*/
    });
    OPTION_TEMPLATE.series[0].color = COLOR_LIST;
  }

  OPTION_TEMPLATE.series[0].data = dataList;
  return OPTION_TEMPLATE;
}

